<template>
	<view style="width: 100%;display: flex;flex-direction: column;">
		<view
			style="width: 100%;display: flex;justify-content: center;color: #d3d3d3;font-size: 20rpx;margin-top: 20rpx;"
			v-if="index%8 == 0">
			{{$u.timeFormat(info.time, 'mm-dd hh:MM:ss')}}
		</view>
		<view v-if="$store.state.user.user.id != info.uid" style="width: 100%;display: flex;padding: 15rpx;">
			<u-avatar @click="gofriend" mode="square" size="80"
				:src="$store.state.common.systemInfo.fileurl + 'avatar/' + info.toid + '.jpg'"></u-avatar>
			<zb-popover placement="top-start" type="longpress" :handleLongpress="handleLongpress" :options="actionss"
				ref="Popover" @select="csitemfunc" actionsDirection="horizontal" style="">
				<view style="width: 100%;display: flex;">
					<image src="/static/images/leftc.png" style="width: 25rpx;position: relative;left: 7rpx;top: 10px;"
						mode="widthFix"></image>
					<view
						style="max-width: 350rpx;min-height: 70rpx; display: flex;flex-wrap: wrap;white-space: pre-wrap;padding: 10rpx;border-radius: 8rpx;background: white;align-items: center;">
						<u-image @click="showbig" :src="$store.state.common.systemInfo.fileurl + info.content" style="min-width: 200rpx;width: 100%;" mode="widthFix"></u-image>
					</view>
				</view>
			</zb-popover>
		</view>

		<view v-else style="width: 100%;display: flex;padding: 15rpx;flex-direction: row-reverse;">

			<u-avatar mode="square" size="80"
				:src="$store.state.common.systemInfo.fileurl + 'avatar/' + info.toid + '.jpg'"></u-avatar>
			<zb-popover placement="top-end" type="longpress" :handleLongpress="handleLongpress" :options="actions"
				ref="Popover" @select="csitemfunc" actionsDirection="horizontal" style="">
				<view style="width: 100%;display: flex;flex-direction: row-reverse;">
					<image src="/static/images/rightc.png"
						style="width: 25rpx;position: relative;right: 7rpx;top: 10px;" mode="widthFix"></image>
					<view
						style="max-width: 350rpx;min-height: 70rpx;display: flex;flex-wrap: wrap;white-space: pre-wrap;padding: 10rpx;border-radius: 8rpx;background: #cff1ff;align-items: center;">
						<u-image @click="showbig" :src="$store.state.common.systemInfo.fileurl + info.content" style="min-width: 200rpx;width: 100%;" mode="widthFix"></u-image>
					</view>
				</view>
			</zb-popover>
		</view>
		
		
	</view>
</template>

<script>
	import {
		mapState
	} from 'vuex';
	import {
		pub
	} from '@/common/event';
	import moment from 'moment';
	export default {
		data() {
			return {
				actionss: [{
						text: '转发',
					},
					{
						text: '收藏',
					},
				],
				actions: [{
						text: '转发',
					},
					{
						text: '撤回',
					},
					{
						text: '收藏',
					},
				]
			}
		},
		mounted() {
			if (moment().valueOf() - this.info.time > 60000) {
				this.actions = [{
						text: '转发',
					},
					{
						text: '收藏',
					},
				]
			}
		},
		props: {
			info: {
				type: Object,
				default: () => {
					return {}
				}
			},
			index: {
				type: Number,
				default: 0
			}
		},
		computed: {
			...mapState({
				list: (state) => {

				}
			})
		},
		methods: {
			showbig:function(){
				const src = this.$store.state.common.systemInfo.fileurl + this.info.content
				uni.previewImage({
					urls:[src]
				})
			},
			handleLongpress: function(e) {
				console.log(e)
				if (moment().valueOf() - this.info.time > 60000) {
					this.actions = [{
							text: '转发',
						},
						{
							text: '收藏',
						},
					]
				}
			},
			gofriend:function(){
				const list = this.$store.state.friend.list
				const user = this.$store.state.user.user
				const ret = list.find(e=>{
					return e.fid == this.info.uid
				})
				if(ret){
					uni.navigateTo({
						url:"/pages/friend/detail?id="+this.info.uid
					})
				}else{
					uni.navigateTo({
						url:"/pages/friend/friend?id="+this.info.uid
					})
				}
			},
			csitemfunc: async function(ex) {
				const e = ex.text
				console.log(e)
				if(e == "转发"){
					uni.navigateTo({
						url:"/pages/friend/sharemessage?id="+this.info.id
					})
				}
				if(e == "撤回"){
					const ret = await this.$u.delete(`chat/chat/removemessage/${this.info.id}`)
					uni.showToast({
						title:"已撤回",
					})
				}
				if(e == "收藏"){
					const ret = await this.$u.post(`chat/chat/collect`,this.info)
					pub("collect_done",ret.data)
					uni.showToast({
						title:"已收藏"
					})
				}
			},
		}
	}
</script>

<style>
</style>